Page({
  /**
   * 页面的初始数据
   */
  data: {
    emptyType: false,
    getdata: [],
    key: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.getData()
    this.getKey()
    
  },
    
  getKey() {
    let that = this
    wx.cloud.callFunction({
      name: 'getKey',
      data: {
        name: 'histroyToday'
      }
    }).then(res => {
      console.log(res.result.data[0].key)
      that.setData({
        key: res.result.data[0].key
      })
      this.getData()
    })
  },
  getData() {
    // this.getKey()
    wx.showLoading({
      title: '加载中',
    });
    let that = this
    var date = new Date();
    let month = date.getMonth() + 1
    let day = date.getDate()
    wx.request({
      url: "https://v.juhe.cn/todayOnhistory/queryEvent.php?key="+that.data.key+"&date=" + month + '/' + day,
      data: {
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.reason == "success") {
          that.setData({
            emptyType: true,
            getdata: res.data.result
          })
        } else {
          that.setData({
            emptyType: false
          })
        }
      }
    })
  },
  // 跳转详情页
  godetails(e) {
    console.log(e.currentTarget.dataset.id)
    wx.navigateTo({
      url: './details?id=' + e.currentTarget.dataset.id,
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})